package com.zb.internetSpider.gui.panel;

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Font;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.annotation.Resource;
import javax.swing.JButton;
import javax.swing.JCheckBox;
import javax.swing.JLabel;
import javax.swing.JList;
import javax.swing.JPanel;
import javax.swing.JTable;
import javax.swing.table.DefaultTableColumnModel;
import javax.swing.table.DefaultTableModel;
import javax.swing.table.TableColumn;
import javax.swing.table.TableColumnModel;
import javax.swing.table.TableModel;

import org.springframework.stereotype.Component;

import com.zb.internetSpider.entity.Menu;
import com.zb.internetSpider.gui.SpiderComponent;
import com.zb.internetSpider.gui.SpiderContainer;
import com.zb.internetSpider.gui.jtable.SpiderTableModel;
import com.zb.internetSpider.service.api.MenuService;

@Component("menuManager")
public class MenuManagerPanel extends AbstractSpiderContentPanel implements ActionListener {
	
	/**
	 * @Fields serialVersionUID : TODO
	 */
	private static final long serialVersionUID = 2063678026751936437L;
	
	private JTable table;

	public MenuManagerPanel( MenuService menuService) {
		// TODO Auto-generated constructor stub
		 // 表头（列名）
		this.jPanel = new JPanel(new BorderLayout());
		Object columnNames[] = {"选中","编号", "名称", "序号", "级别", "父节点"};

        // 表格所有行数据
		Menu[] menus = menuService.list().toArray(new Menu[0]);
		
		
		Object[][] rowData = new Object[menus.length][6];
		for(int i = 0; i< menus.length; i++) {
			rowData[i][0] = new Boolean(false);
			rowData[i][1] = menus[i].getMenuId();
			rowData[i][2] = menus[i].getMenuName();
			rowData[i][3] = menus[i].getMenuSort();
			rowData[i][4] = menus[i].getMenuLevel();
			rowData[i][5] = menus[i].getMenuParentId();
		}
		
        // 创建一个表格，指定 所有行数据 和 表头
        this.table = new JTable(rowData, columnNames);
//        this.t
        
        TableColumn tc = table.getColumnModel().getColumn(0);
        tc.setCellEditor(table.getDefaultEditor(Boolean.class));
        tc.setCellRenderer(table.getDefaultRenderer(Boolean.class));
        
        table.setFont(new Font("楷体", Font.PLAIN, 18));
        table.setRowHeight(32);

        // 把 表头 添加到容器顶部（使用普通的中间容器添加表格时，表头 和 内容 需要分开添加）
        jPanel.add(table.getTableHeader(), BorderLayout.NORTH);
        // 把 表格内容 添加到容器中心
        jPanel.add(table, BorderLayout.CENTER);
        JButton button = new JButton("修改");
        button.addActionListener(this);
        jPanel.add(button, BorderLayout.SOUTH);
		super.setViewportView(jPanel);
	}

	@Override
	public void setSpiderContainers(SpiderContainer... containers) {
		// TODO Auto-generated method stub

	}

	@Override
	public void setSpiderComponents(SpiderComponent... components) {
		// TODO Auto-generated method stub

	}

	@Override
	public SpiderContainer[] getSpiderContainers() {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public SpiderComponent[] getSpiderComponents() {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public int SpiderContainersCount() {
		// TODO Auto-generated method stub
		return 0;
	}

	@Override
	public int SpiderComponentsCount() {
		// TODO Auto-generated method stub
		return 0;
	}

	@Override
	public void setFont(Font font, Color color) {
		// TODO Auto-generated method stub

	}

	@Override
	public void actionPerformed(ActionEvent e) {
		// TODO Auto-generated method stub
		System.out.println(e.getActionCommand());
		table.setEditingColumn(1);
	}

}
